<template >
    <div class="wrap-table fllow-manage">
        <el-form ref="form" :model="searchData" label-width="100px" class="clearfix flex-div">
            <el-form-item label="门诊日期" class="" label-width="70px" style="width:340px">
                <div class="block">
                    <el-date-picker
                            v-model="timeDate"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            value-format="yyyy-MM-dd"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :picker-options="pickerOptions">
                    </el-date-picker>
                </div>
            </el-form-item>
            <el-form-item label="所在地区" class=" item-right" style="width:200px">
                <el-select v-model="searchData.districtNo" placeholder="请选择" @change="changeDis" clearable :disabled="JSON.parse(UserDic).IsCommunityOnly=='1'">
                    <el-option
                            v-for="item in optionDiq"
                            :key="item.DistrictName"
                            :label="item.DistrictName"
                            :value="item.DistrictNo">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="所在社区" class=" item-right" style="width:170px">
                <el-select v-model="CtyIds" placeholder="请选择" @change="Commutysp" clearable :disabled="JSON.parse(UserDic).IsCommunityOnly=='1'">
                    <el-option
                            v-for="item in optionsData"
                            :key="item.SYS_ID"
                            :label="item.CName"
                            :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="当前干预强度" label-width="110px" class=" item-right" style="width:180px">
                <el-select v-model="searchData.currentIntensityOfIntervention" clearable placeholder="请选择">
                    <el-option
                            v-for="item in options9"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="门诊时研究阶段" label-width="120px" class="" style="width:220px">
                <el-select v-model="searchData.period" clearable placeholder="请选择">
                    <el-option
                            v-for="item in options2sp"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="哺乳顾问" label-width="100px" class=" item-right" style="width:200px">
                <el-select v-model="searchData.NurseId" clearable placeholder="请选择">
                    <el-option
                            v-for="item in optionsNurse"
                            :key="item.SYS_ID"
                            :label="item.icons"
                            :value="item.SYS_ID">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="试验类型" class=" item-right" style="width:260px">
                <el-select v-model="searchData.testType" clearable placeholder="请选择">
                    <el-option
                            v-for="item in options6"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="对象状态" class="" style="width:190px">
                <el-select v-model="searchData.userState" clearable placeholder="请选择">
                    <el-option
                            v-for="item in options4"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item class="" label="">
                <el-input v-model="searchData.keyWord" style="width: 210px;margin-left: -60px;" placeholder="研究对象手机号、研究编号"></el-input>
            </el-form-item>
                <!--</div>-->
            <!--</transition>-->
            <div class="flex-r-but">
                <el-button v-if="RoleGroup=='9'" type="success" @click="addPosition"
                           class="  mg-lr-20 pd-bt">添加门诊记录
                </el-button>
                <el-button type="primary" @click="checkList" class=" mg-lr-20 pd-bt">查询</el-button>
            </div>

        </el-form>
        <!---->
        <template>
            <el-table
                    :data="tableData"
                    border
                    id="outtableFirst"
                    v-loading="loading"
                    element-loading-text="加载中"
                    style="width: 100%">
                <el-table-column
                        prop="VisitDate"
                        align="center"
                        label="门诊日期"
                        min-width="160">
                    <template  slot-scope="scope">
                        <span class="excelHidden">({{scope.row.VisitDate}})</span>
                        <el-date-picker
                                v-model="scope.row.VisitDate"
                                :clearable="false"
                                @change="changeFollowUpDate(scope.row,scope.row.VisitDate)"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="选择日期">
                        </el-date-picker>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="FollowUpTime"
                        label="开始时间"
                        align="center"
                        min-width="120">
                    <template  slot-scope="scope">
                        <span class="excelHidden">({{scope.row.VisitStartTime}})</span>
                        <el-time-select
                                v-model="scope.row.VisitStartTime"
                                :clearable="false"
                                @change="changeFollowUpDateOne(scope.row,scope.row.VisitStartTime)"
                                :picker-options="{start: '08:00', step: '00:15',end: '21:30'}"
                                placeholder="">
                        </el-time-select>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="Nurse"
                        label="哺乳顾问"
                        align="center"
                        min-width="120">
                    <template slot-scope="scope">
                        <span class="excelHidden">({{scope.row.Nurse}})</span>
                        <el-select v-model="scope.row.Nurse" placeholder="请选择" @change="changeNurse(scope.row,scope.row.Nurse)">
                            <el-option
                                    v-for="item in optionsNurse"
                                    :key="item.SYS_ID"
                                    :label="item.icons"
                                    :value="item.icons">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="Surname"
                        label="姓名首字母"
                        align="center"
                        min-width="100">
                </el-table-column>
                <el-table-column
                        label="手机号"
                        align="center"
                        min-width="100">
                    <template slot-scope="scope">
                        <el-tooltip :content="scope.row.Mobile" placement="top">
                            <span>{{scope.row.Mobile |mobileFilter}}</span>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="ResearchNo"
                        label="研究编号"
                        align="center"
                        min-width="100">
                </el-table-column>
                <el-table-column
                        prop="VisitPeriod"
                        label="门诊时研究阶段"
                        :formatter="PeriodFilter"
                        align="center"
                        min-width="120">
                </el-table-column>
                <el-table-column
                        prop="VisitIntensityOfIntervention"
                        label="门诊时干预强度"
                        :formatter="IntensityFilter"
                        align="center"
                        min-width="150">
                </el-table-column>
                <el-table-column
                        prop="CurrentIntensityOfIntervention"
                        label="当前干预强度"
                        :formatter="IntensityFilter"
                        align="center"
                        min-width="150">
                </el-table-column>
                 <el-table-column
                        prop="DistrictName"
                        :formatter="DistrictNameFilter"
                        label="所在地区"
                        align="center"
                        min-width="100">
                </el-table-column>
                <el-table-column
                        prop="CName"
                        label="所在社区"
                        align="center"
                        min-width="100">
                </el-table-column>
                <el-table-column
                        prop="UserState"
                        label="对象状态"
                        :formatter="UserStateFilter"
                        align="center"
                        min-width="100">
                </el-table-column>
                <el-table-column
                        min-width="140"
                        fixed="right"
                        align="center"
                        label="门诊处方">
                    <template  slot-scope="scope">
                       <el-button v-if="scope.row.IsDraft=='1'" size="small" type="text"
                                  @click="handleTable(scope.row)">查看</el-button>
                        <el-button style="color: #f00" v-else-if="scope.row.IsDraft=='0'" size="small" type="text"
                                   @click="handleTable(scope.row)">去修改</el-button>
                        <el-button style="color: #f00" v-else size="small" type="text"  @click="handleTable(scope.row)">生成</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </template>
        <!--分页-->
        <div class="block mg-20-auto pagination-fixed">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="pageId"
                    :page-sizes="[10, 20, 30, 40,80,100,200,500]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
        <el-dialog title="添加母乳喂养门诊记录" :visible.sync="dialogPation" :append-to-body="true" top="0" width="60%"
                   :close-on-click-modal="false">
            <el-form :model="FormPation" :rules="rules2" label-position="left" ref="FormPation" label-width="70%"
                     class="demo-ruleForm">
                <el-form-item label="研究对象手机号" prop="Mobile">
                    <el-input @blur="getUser" v-model="FormPation.Mobile" placeholder="研究对象手机号"></el-input>
                </el-form-item>
                <div v-show="hasName">
                    <div v-if="FormPation.Period=='1'">
                        <el-form-item label="姓名首字母">
                            <el-input v-model="FormPation.Surname" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="研究编号">
                            <el-input v-model="FormPation.ResearchNo" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="干预强度">
                            <el-input v-model="FormPation.Inlabel" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="研究阶段">
                            <el-input v-model="FormPation.PeriodN" :disabled="true"></el-input>
                        </el-form-item>
                    </div>
                    <div v-else-if="FormPation.Period=='2'">
                        <el-form-item label="姓名首字母">
                            <el-input v-model="FormPation.Surname" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="研究编号">
                            <el-input v-model="FormPation.ResearchNo" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="干预强度">
                            <el-input v-model="FormPation.Inlabel" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="研究阶段">
                            <el-input v-model="FormPation.PeriodN" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="预产期">
                            <el-input v-model="FormPation.ExpectedDate" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="纠正预产期">
                            <el-input v-model="FormPation.RecorrectExpecteDate" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="孕周">
                            <el-input v-model="FormPation.BirthWeek" :disabled="true"></el-input>
                        </el-form-item>
                    </div>
                    <div v-else>
                        <el-form-item label="姓名首字母">
                            <el-input v-model="FormPation.Surname" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="研究编号">
                            <el-input v-model="FormPation.ResearchNo" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="干预强度">
                            <el-input v-model="FormPation.Inlabel" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="研究阶段">
                            <el-input v-model="FormPation.PeriodN" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="出生日期">
                            <el-input v-model="FormPation.ChildBirthDate" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="性别">
                            <el-input v-model="FormPation.sex" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="年龄">
                            <el-input v-model="FormPation.ChildAge" :disabled="true"></el-input>
                        </el-form-item>
                    </div>
                </div>
                <el-form-item label="门诊日期" prop="VisitDate">
                    <el-date-picker
                            v-model="FormPation.VisitDate"
                            :clearable="false"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="开始时间" prop="VisitStartTime">
                    <el-time-select
                            v-model="FormPation.VisitStartTime"
                            :clearable="false"
                            :picker-options="{start: '08:00', step: '00:15',end: '21:30'}"
                            placeholder="">
                    </el-time-select>
                </el-form-item>
                <el-form-item label="结束时间" prop="VisitOverTime">
                    <el-time-select
                            v-model="FormPation.VisitOverTime"
                            :clearable="false"
                            :picker-options="{start: '08:00', step: '00:15',end: '21:30'}"
                            placeholder="">
                    </el-time-select>
                </el-form-item>
                <el-form-item label="哺乳顾问">
                    <el-input v-model="userIcon" :disabled="true"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogPation = false">取 消</el-button>
                <el-button type="primary" @click="savePation('FormPation')">确认</el-button>
            </div>
        </el-dialog>
        <!--oneStep-->
        <el-dialog title="母乳喂养门诊处方" :visible.sync="dialogFormAnli" :append-to-body="true" top="0" width="60%"
                   :close-on-click-modal="false">
                <div style="margin-right: 20px;overflow-x: hidden">
                    <p style="margin-bottom: 15px;font-weight: bold">研究对象：{{formPoint.Surname}}({{formPoint.ResearchNo}}) <span
                            style="padding-left: 15px;">研究阶段：{{formPoint.VisitPeriod |PeriodFilters}}</span>
                        <span style="padding-left: 15px;">手机号：{{formPoint.Mobile |mobileFilter}}</span>
                    </p>
                    <p>门诊时间：{{formPoint.VisitDate}} <span>{{formPoint.VisitStartTime}}</span></p>
                    <el-form :model="FormAnli" :rules="rules1" label-position="left" ref="FormAnli" label-width="40%"
                             class="demo-ruleForm">
                        <el-form-item label="是否在产前进行过母乳喂养咨询（热线/门诊）">
                            <el-radio-group v-model="FormAnli.HasBreastfeedingCounseling">
                                <el-radio label="1">是</el-radio>
                                <el-radio label="2">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="如果是，主要原因" v-if="FormAnli.HasBreastfeedingCounseling=='1'">
                            <el-input v-model="FormAnli.BreastfeedingCounselingReason"></el-input>
                        </el-form-item>
                        <el-form-item label="咨询原因-母亲" class="is-required" prop="MotherReason">
                            <el-checkbox-group v-model="MotherReason">
                                <el-checkbox label="乳头疼痛"></el-checkbox>
                                <el-checkbox label="乳头平坦或者内陷"></el-checkbox>
                                <el-checkbox label="其他乳头原因（如感染、皲裂）"></el-checkbox>
                                <el-checkbox label="涨奶"></el-checkbox>
                                <el-checkbox label="乳腺炎"></el-checkbox>
                                <el-checkbox label="乳腺堵塞"></el-checkbox>
                                <el-checkbox label="乳房手术史"></el-checkbox>
                                <el-checkbox label="服用了影响母乳喂养的药物"></el-checkbox>
                                <el-checkbox label="母乳不够"></el-checkbox>
                                <el-checkbox label="母乳过多"></el-checkbox>
                                <el-checkbox label="情绪问题"></el-checkbox>
                                <el-checkbox label="回奶"></el-checkbox>
                                <el-checkbox label="自信心问题"></el-checkbox>
                                <el-checkbox label="其他"></el-checkbox>
                            </el-checkbox-group>
                            <el-input v-if="MotherReason.indexOf('其他')>-1"
                                      v-model="FormAnli.MotherReasonOther"  placeholder="限50字"></el-input>
                        </el-form-item>
                        <el-form-item label="咨询原因-宝宝"  class="is-required" prop="ChildReason">
                            <el-checkbox-group v-model="ChildReason">
                                <el-checkbox label="高胆红素血症"></el-checkbox>
                                <el-checkbox label="先天性疾病"></el-checkbox>
                                <el-checkbox label="早产"></el-checkbox>
                                <el-checkbox label="体重增长不足"></el-checkbox>
                                <el-checkbox label="舌头因素"></el-checkbox>
                                <el-checkbox label="口腔感染"></el-checkbox>
                                <el-checkbox label="其他"></el-checkbox>
                            </el-checkbox-group>
                            <el-input v-if="ChildReason.indexOf('其他')>-1"
                                      v-model="FormAnli.ChildReasonOther"  placeholder="限50字"></el-input>
                        </el-form-item>


                        <el-form-item label="主要问题" class="is-required"  prop="Reason">
                            <el-checkbox-group v-model="Reason">
                                <el-checkbox label="错误的哺乳姿势或含接不良"></el-checkbox>
                                <el-checkbox label="婴儿吸吮功能障碍"></el-checkbox>
                                <el-checkbox label="舌系带缩短"></el-checkbox>
                                <el-checkbox label="口腔解剖异常"></el-checkbox>
                                <el-checkbox label="乳头异常"></el-checkbox>
                                <el-checkbox label="吸奶器相关损伤"></el-checkbox>
                                <el-checkbox label="皮肤病"></el-checkbox>
                                <el-checkbox label="感染"></el-checkbox>
                                <el-checkbox label="血管痉挛"></el-checkbox>
                                <el-checkbox label="乳腺导管堵塞"></el-checkbox>
                                <el-checkbox label="吸吮频率不够"></el-checkbox>
                                <el-checkbox label="乳腺导管受压"></el-checkbox>
                                <el-checkbox label="过度乳房按摩"></el-checkbox>
                                <el-checkbox label="睡眠不足"></el-checkbox>
                                <el-checkbox label="过度焦虑"></el-checkbox>
                                <el-checkbox label="家庭支持系统缺乏"></el-checkbox>
                                <el-checkbox label="哺乳知识缺乏"></el-checkbox>
                                <el-checkbox label="其他"></el-checkbox>
                            </el-checkbox-group>
                            <el-input v-if="Reason.indexOf('其他')>-1"
                                      v-model="FormAnli.ReasonOther"  placeholder="限50字"></el-input>
                        </el-form-item>
                        <el-form-item label="目标" prop="Target" class="aloneItem is-required">
                            <el-input type="textarea" v-model="FormAnli.Target" placeholder="限500字"></el-input>
                        </el-form-item>
                        <el-form-item label="建议1" prop="Advice1" class="aloneItem is-required">
                            <el-input type="textarea" v-model="FormAnli.Advice1" placeholder="限500字"></el-input>
                        </el-form-item>
                        <el-form-item label="建议2(选填)" class="aloneItem ">
                            <el-input type="textarea" v-model="FormAnli.Advice2" placeholder="限500字"></el-input>
                        </el-form-item>
                       
                        <el-form-item label="提供资源" prop="ProvideResources" class="aloneItem is-required">
                            <el-input type="textarea" v-model="FormAnli.ProvideResources" placeholder="限500字"></el-input>
                        </el-form-item>
                    </el-form>
                </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormAnli = false">关 闭</el-button>
                <el-button type="primary" v-if="FormAnli.IsDraft!='1'" @click="tableSure('FormAnli','0')">保存草稿
                </el-button>
                <el-button type="primary"  v-if="FormAnli.IsDraft!='1'" @click="tableSure('FormAnli','1')">提交
                </el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import {mapGetters} from 'vuex'
import {DIC_PERIODA,filterPeriod} from '@/utils/localDic'
export default {
    data() {
        return {
            searchData:{
                followUpType:'',
                appointState:'',
                followUpState:'',
                userState:'',
                groupType:'',
                keyWord:'',
                period:'',
                districtNo:'',
	            intensityOfIntervention:'',
	            currentIntensityOfIntervention:'',
                NurseId:'',
                communityId:'', // 社区id
                testType: '2', // 试验类型
                NurseId:''
            },
            // districtNo:'310105',
            CtyIds:'',
            timeDate:[],
            optionDiq:[],
            optionsData:[],  //社区数据
            Companions:[],
            subDisabled:false,
            dialogForm1:false,
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                    picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                            onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                            onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }],
            },
            pageId:1,
            total:null,
	        dialogPation:false,
            loading:true,
            pageSize:10,
            tableData:[],
	        optionPC:[{value:'母乳喂养',label:'母乳喂养'},{value: '环境', label: '环境'},{value: '体育锻炼', label: '体育锻炼'},{value:
                    '睡眠', label: '睡眠'},{value: '营养', label: '营养'},{value: '健康状态', label: '健康状态'},{value: '吸烟', label:
                    '吸烟'},{value: '支持网络', label: '支持网络'},{value: '榜样', label: '榜样'}],
            optionP: [{value: '母乳喂养', label: '母乳喂养'}, {value: '环境', label: '环境'}, {value: '营养', label: '营养'}, {value: '身体活动', label: '身体活动'}, {value: '心理健康', label: '心理健康'}, {value: '睡眠', label: '睡眠'}, {value: '吸烟', label: '吸烟'}],
            options1: [{value: '', label: '全部'},{value: '1', label: '面对面'}, {value: '2', label: '电话'}],
            options5:[{value: '1', label: '面对面'}, {value: '2', label: '电话'}],
            options2: [{value: '', label: '全部'},{value: '0', label: '待确认'},{value: '1', label: '已确认'}, {value: '2', label: '已取消'}],
            options2s: [{value: '0', label: '待确认'},{value: '1', label: '已确认'}, {value: '2', label: '已取消'}],
            options3: [{value: '', label: '全部'},{value: '1', label: '已完成'}, {value: '0', label: '待完成'}, {value: '2', label: '已取消'}, {value: '3', label: '爽约'}],
            options3s: [{value: '1', label: '已完成'}, {value: '0', label: '待完成'},{value: '2', label: '已取消'}, {value: '3', label: '爽约'}],
            options4: [{value: '', label: '全部'},{value: '1', label: '活跃'},{value: '2', label: '不活跃'}],
            optionss6: [{value: '', label: '全部'},{value: '1', label: 'A'}, {value: '2', label: 'B'}],
            options6: [{value: '', label: '全部'},{value: '0', label: '预试验'},{value: '1', label: '正式试验'},{value: '2', label: '预试验+正式试验'}],
            options2sp:DIC_PERIODA,
            options9: [{value: '', label: '全部'},{value: '1', label: 'AA'}, {value: '2', label: 'A'}],
            FollowUpTypeFilter(row, column, cellValue, index){
                return cellValue==1?'面对面':'电话'
            },
            UserStateFilter_move(row, column, cellValue, index){
                return cellValue==1?'已发送':'草稿'
            },
            PeriodFilter(row, column, cellValue, index){
                return filterPeriod(cellValue)
            },
            ResultFilter(row, column, cellValue, index){
                switch(cellValue){
                    case '1':
                        return '目标达成';
                        break;
                    case '2':
                        return '目标部分达成'
                        break;
                    case '3':
                        return '没有改变';
                        break;
                    case '4':
                        return '情况更糟'
                }
            },
             DistrictNameFilter(row, column, cellValue, index){
                return cellValue ||'-'
            },
            IntensityFilter(row, column, cellValue, index){
                return cellValue==1?'AA':'A'
            },
            AppointFilter(row, column, cellValue, index){
                return cellValue==1?'已预约':(cellValue==0?'待确认':'已取消')
            },
            FollowUpFilter(row, column, cellValue, index){
                return cellValue==1?'已完成':'待完成'
            },
            maxHeight:'',
            showtexts:['一点也没有', '', '有一点', '', '完全有信心'],
            showtexts2:['不重要', '', '一般', '', '非常重要'],
            sysId:'',
            ResearchObjectId:'',
            ScheduleId:'',
            showActive:false,
            dialogForm2:false,
            tableDataQ:[],
            pageIdQ:1,
            totalQ:null,
            loadingQ:true,
            SYS_IDs:'',
            pageSizeQ:5,
            tablerow:null,
            optionsNurse:[],
            copyObject:null,
            onOFFsub:false,
            GroupTypeFilter(row, column, cellValue, index){
                return cellValue=='1'?'A':'B'
            },
	        mobileTel:'',
	        FormPation:{
		        BirthWeek:'',
		        Surname:'',
		        ChildBirthDate:'',
		        BirthWeight:'',
		        ExpectedDate:'',
		        RecorrectExpecteDate:'',
		        ResearchNo:'',
		        IntensityOfIntervention:'',
		        Inlabel:'',
                sex:'',
		        Mobile:'',
	            PeriodN:'',
                ChildAge:'',
            },
            rules2:{
	            Mobile:[
		            { required: true,message: '必填项',trigger: 'blur'}
	            ],
	            VisitDate:[
		            { required: true,message: '必填项',trigger: 'blur'}
	            ],
	            VisitStartTime:[
		            { required: true,message: '必填项',trigger: 'blur'}
	            ],
            },
            rules1:{
	            Reason:[
                    { required: true,message: '必填项',trigger: 'blur'}
                ],
	            ProvideResources:[
                    { trigger: 'blur',required: true,message: '必填项',}
                ],
	            Advice1:[
                    { trigger: 'blur',required: true,message: '必填项',}
                ],
	            Target:[
                    { trigger: 'blur',required: true,message: '必填项',}
                ],
	            ChildReason:[
                    { trigger: 'blur',required: true,message: '必填项',}
                ],
	            MotherReason:[
                    { trigger: 'blur',required: true,message: '必填项',}
                ],
            },
            dialogFormAnli:false,
            FormAnli:{
	            MotherReason:'',
	            ChildReason:'',
	            ChildReasonOther:'',
	            Reason:'',
	            Target:'',
	            Advice1:'',
	            Advice2:'',
	            Advice3:'',
	            ProvideResources:'',
                sex:'',
                ReasonOther:'',
                ChildReason:'',
                Reason:'',
                ChildReasonOther:'',
            },
	        MotherReason:[],
            ChildReason:[],
            Reason:[],
            loadingRedcore:true,
            formPoint:{},
            dataRow:{},
            rowOff:false,
            diaLoading:true,
	        hasCount:false,
	        hasName:true,
            addOff:false,
        }
    },
    filters:{
        IsFillInQuestionFilter(cellValue){
            if(cellValue==1){
                return '已完成'
            }
            else if(cellValue==0){
                return '未完成'
            }
            else{
                return '-'
            }
        },
	    FollowUpType(cellValue){
		    if(cellValue==1){
			    return '面对面'
		    }
		    else if(cellValue==2){
			    return '电话'
		    }
		    else{
			    return '-'
		    }
	    },
        mobileFilter(cellValue) {
        	if(cellValue){
		        return cellValue.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
            }
        },
	    AppointState(cellValue){
		    if(cellValue=='0'){
			    return '待确认'
		    }
        	else if(cellValue=='1'){
			    return '已确认'
		    }
		    else if(cellValue=='2'){
			    return '已取消'
		    }
		    else{
			    return '-'
		    }
	    },
	    FollowUpState(cellValue){
		    if(cellValue=='0'){
			    return '待完成'
		    }
		    else if(cellValue=='1'){
			    return '已完成'
		    }
		    else if(cellValue=='2'){
			    return '已取消'
		    }
		    else if(cellValue=='3'){
			    return '爽约'
            }
		    else{
			    return '-'
		    }
	    },
        FollowUpTypeFilter(cellValue){
            return cellValue==1?'面对面':'电话'
        },
	    PeriodFilters(cellValue){
		   return filterPeriod(cellValue)
	    },
    },
    created() {
    },
    computed:{
        ...mapGetters([
                'userIcon',
                'userId',
                'token',
                'RoleGroup',
                'UserDic'
            ]),
	    yunzhous:function(){
		    return parseInt((WeeksBetw(new Date,this.LASTTIME))/7)
	    },
        yunDay(){
        	return parseInt((WeeksBetw(new Date,this.LASTTIME))%7)
        }
    },
    async mounted(){
        let that=this;
        let now = new Date();
        let nowTime = now.getTime() ;
        let day = now.getDay();
        if(day==0){     //西方从周日算为第一天    2018/10/28
            day=7
        }
        let oneDayLong = 24*60*60*1000 ;
        let MondayTime = nowTime - (day-1)*oneDayLong  ;
        let SundayTime =  nowTime + (7-day)*oneDayLong ;
        let monday = dateForm(new Date(MondayTime));
        let sunday = dateForm(new Date(SundayTime));
        that.timeDate= [
            monday,
            sunday
        ];   //初始化时间范围
	    await that.GetCommunityDistrict()
		that.searchData.districtNo=JSON.parse(that.UserDic).DistrictNo||that.searchData.districtNo||''
		if(JSON.parse(that.UserDic).IsCommunityOnly=='1'){
			await that.getComselectList()
			that.searchData.communityId=JSON.parse(that.UserDic).CommunityId||''
			if(that.searchData.communityId){
                 that.CtyIds=that.optionsData.find(val=>{
                     return val.SYS_ID==JSON.parse(that.UserDic).CommunityId
                 }).CName||''
             }
		}
        that.getList()
        that.GetNurse()// 获取干预护士
    },
    beforeMount:function() {
        let that=this;
        let appHeight=$(window).height();
        let autoheight=(appHeight-288)+'px'
        that.maxHeight=autoheight
    },
    methods: {
	    addPosition(){    //添加门诊
            this.dialogPation=true
		    this.$nextTick(()=> {
			    this.$refs['FormPation'].resetFields();
			    this.FormPation={
				    VisitDate:dateForm(new Date())
                }
		    })
        },
	    savePation(formName){    //保存门诊
		    if(this.addOff){
			    return false
		    }
		    this.addOff=true
		    this.$refs[formName].validate((valid) =>{
			    if (valid) {
				    this.service({
					    url: "/ResearchObject/SaveBreastOutpatient",
					    method: "post",
					    data: {
                            ...this.FormPation,
						    Nurse:this.userIcon,
						    NurseId:JSON.parse(this.UserDic).SYS_ID,
						    Creater:this.userIcon,
						    CreaterId:JSON.parse(this.UserDic).SYS_ID,
					    }
				    }).then(response => {
                        this.dialogPation=false
					    this.$message({
						    message: '添加成功',
						    type: 'success'
					    });
                        this.getList()
					    this.addOff=false
				    }).catch(data => {
					    this.addOff=false
				    });
			    }
			    else{
				    this.addOff=false
                }
		    })
        },
        async GetCommunityDistrict(){    //获取社区行政区
            let that = this;
            await that.service({
                url: "/Dic/GetCommunityDistrict",
                method: "get",
                params: {
                }
            }).then(response => {
                that.optionDiq=response.dtData;
            })
            .catch(data => {

            });
        },
        // changeCops:function(val){  //多选框
        //   //  this.FormAnli.Companions=val.join(',')
        // },
	    getUser(e){   //获取user
	    	if(!(/^1[3|4|5|7|8][0-9]{9}$/).test(e.target.value)){
			    this.$message({
				    message: '请输入正确的手机号',
				    type: 'warning'
			    });
			    return false
            }
		    this.service({
			    url: "/ResearchObject/GetResearchObjectByMobile",
			    method: "get",
			    params: {
				    mobileTel:e.target.value
			    }
		    }).then(response => {
		    	if(response.dtData.length>0){
		    		if(response.dtData[0].GroupType!='1'){
					    this.$message({
						    message:'不可输入B组研究对象手机号码',
						    type:'info'
					    })
                        return false
                    }
				    this.FormPation={
					    BirthWeek:'',
					    Surname:response.dtData[0].Surname,
					    ChildBirthDate:response.dtData[0].ChildBirthDate||'',
					    BirthWeight:response.dtData[0].BirthWeight||'',
					    ExpectedDate:response.dtData[0].ExpectedDate||'',
					    RecorrectExpecteDate:response.dtData[0].RecorrectExpecteDate||'',
					    ResearchNo:response.dtData[0].ResearchNo||'',
					    IntensityOfIntervention:response.dtData[0].IntensityOfIntervention||'',
					    Inlabel:'',
					    ChildAge:response.dtData[0].ChildAge||'',
					    sex:'',
					    VisitPeriod:response.dtData[0].Period,
					    VisitIntensityOfIntervention:response.dtData[0].IntensityOfIntervention||'',
					    Mobile: this.FormPation.Mobile,
					    PeriodN:'',
					    Period:response.dtData[0].Period||'',
					    ChildSex:response.dtData[0].ChildSex||'',
				    }
                    delete this.FormPation.SYS_ID
				    this.FormPation.IntensityOfIntervention=='1'?this.FormPation.Inlabel='AA':this.FormPation.Inlabel='A'
                    try{
	                    this.FormPation.ResearchObjectId=response.dtData[0].SYS_ID
	                    this.FormPation.Period==1?this.FormPation.PeriodN='孕前期':this.FormPation.Period==2?this.FormPation.PeriodN='怀孕期':this.FormPation.PeriodN='儿童期'
	                    this.FormPation.age=new Date().getFullYear()-parseInt(this.FormPation.ChildBirthDate.substr(0,4))
	                    this.FormPation.ChildSex?this.FormPation.ChildSex=='1'?this.FormPation.sex='男':this.FormPation.ChildSex=='2'?this.FormPation.sex='女':this.FormPation.sex='未说明的性别':''

	                    let dateAlary=new Date(this.FormPation.ExpectedDate)
	                    let LastMenseDate= new
                        Date(dateForm(dateAlary.setMonth(dateAlary.getMonth()-9,dateAlary.getDate()-7)))
	                    this.FormPation.BirthWeek=parseInt((WeeksBetw(new Date,LastMenseDate))/7)+'周'+
		                    parseInt((WeeksBetw(new Date,LastMenseDate))%7)+'天'
                    }catch(e) {
	                    this.FormPation.BirthWeek=parseInt((WeeksBetw(new Date,LastMenseDate))/7)+'周'+
		                    parseInt((WeeksBetw(new Date,LastMenseDate))%7)+'天'
	                    this.FormPation.age=new Date().getFullYear()-parseInt(this.FormPation.ChildBirthDate.substr(0,4))
                    }
                }
                else{
                	this.$message({
                        message:'未查到相关人员',
                        type:'info'
                    })
                	this.mobileTel=''
				    this.FormPation={
					    MotherReason:'',
					    ChildReason:'',
					    ChildReasonOther:'',
					    Reason:'',
					    Target:'',
					    Advice1:'',
					    Advice2:'',
					    Advice3:'',
					    ProvideResources:'',
					    sex:''
                    }
                }

		    }).catch(data => {

		    });
        },
        changeFollowUpDate:function(row,val){
            this.setList(row)
        },
        handleTable:function(row){
            let that=this;
	        that.rowOff=false
	        that.MotherReason=[]
            that.ChildReason=[]
            that.Reason=[]
            that.dialogFormAnli=true;
            that.dataRow=row;
            that.FormAnli={
	            MotherReason:'',
	            ChildReason:'',
	            ChildReasonOther:'',
	            Reason:'',
	            Target:'',
	            Advice1:'',
	            Advice2:'',
	            Advice3:'',
                ProvideResources:'',
                MotherReason:'',
                ReasonOther:'',
                ChildReason:'',
                Reason:'',
                ChildReasonOther:'',
            }
            that.$nextTick(function () {
                that.$refs['FormAnli'].resetFields();
	            that.formPoint=row
	            that.FormAnli.ResearchObjectId=row.ResearchObjectId
	            that.FormAnli.BreastOutpatientId=row.SYS_ID
	            that.service({
		            url: "/ResearchObject/GetBreastPrescription",
		            method: "get",
		            params: {
			            sysId:row.BreastPrescriptionId||'0'
		            }
	            }).then(response => {
		            if(response.dtData.length>0){
			            that.FormAnli=response.dtData[0]
			            that.MotherReason=(that.FormAnli.MotherReason||'').split(',')
                        that.ChildReason=(that.FormAnli.ChildReason||'').split(',')
                         that.Reason=(that.FormAnli.Reason||'').split(',')
		            }
	            }).catch(data => {

	            });
            })

        },
        changeDis(val) {
              this.CtyIds=''
              this.searchData.communityId=''
              this.optionsData= [];
              if(val){
                  this.getComselectList()
              }
        },
        // 获取社区列表
        async getComselectList(){
            let that = this;
            await that.service({
                url: "dic/GetCommunity",
                method: "get",
                params: {
                    cName: "",
                    cGroup: "",
                    districtNo:that.searchData.districtNo||'',
                    pageCount:0,
                    pageSize: 100,
                }
            }).then(resp => {
                if(that.searchData.districtNo && that.searchData.districtNo!=''){
                     that.optionsData=resp.dtData
                }
                else{
                     that.optionsData=[]
                }
                
            }).catch(data => {

            });
        },
        Commutysp (val) {
            this.CtyIds=val.CName
            val.SYS_ID!==undefined?this.searchData.communityId=val.SYS_ID:this.searchData.communityId=''
        },
        tableSure:function(formName,IsDraft){
          let that=this;
          if(that.rowOff){
              return false
          }
          that.FormAnli.MotherReason=that.MotherReason.join(",")
          that.FormAnli.Reason=that.Reason.join(",")
          that.FormAnli.ChildReason=that.ChildReason.join(",")
          that.rowOff=true
          that.$refs[formName].validate((valid) =>{
            if (valid) {
                that.service({
                  url: "/ResearchObject/SaveBreastPrescription",
                  method: "post",
                  data: {
                    ...that.FormAnli,
	                IsDraft:IsDraft,
                    Creater:this.userIcon||'',
                    CreaterId:JSON.parse(this.UserDic).SYS_ID||'',
                  }
                }).then(response => {
                    that.dialogFormAnli=false
                    that.$message({
                      message:'保存成功',
                      type:'success'
                    })
                    that.getList()
                }).catch(data => {});
                that.dialogFormAnli=false
            }
            else {
              that.rowOff=false
              return false
            }
          })
        },
        changeFollowUpDateOne:function(row,val){
            let that=this;
            if(row.AppointState==0){
                this.$confirm('是否将预约状态改为已确认 , 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                   row.AppointState='1';
                   that.setList(row)
                }).catch(() => {
                    that.setList(row)
                });
            }
            else{
                 that.setList(row)
            }
        },
        jumpQuestion:function(row){   //问卷跳转
            let that=this;
            if(row.IsFillInQuestionnaire==undefined){
                return false
            }
            that.$router.push({
                path:'/participant/editor',
                query:{
                    id:row.ResearchObjectId,
                    mobile:row.Mobile,
                    researchNo:row.ResearchNo,
                    isOther:1
                }
            })
        },
        jumpMove:function(row){  //跳转行动计划
            let that=this;
            that.$router.push({
                path:'/participant/editor',
                query:{
                    id:row.ResearchObjectId,
                    mobile:row.Mobile,
                    researchNo:row.ResearchNo,
                    isOther:2
                }
            })
        },
        JumpUserinfo:function(row){
            let that=this;
            that.$router.push({
                path:'/participant/editor',
                query:{
                    id:row.ResearchObjectId,
                    mobile:row.Mobile,
                    researchNo:row.ResearchNo,
                }
            })
        },
        UserStateFilter(row, column, cellValue, index){
            switch (cellValue){
                case '1':
                    return '活跃'
                    break;
                case '2':
                    return '不活跃'
                    break;
                case '3':
                    return '不活跃'
                    break;
                case '4':
                    return '不活跃'
                    break;
                case '5':
                    return '不活跃'
                    break;
            }
        },

        handleSizeChange(val) {       //条数改变
            this.pageSize=val;
            this.getList()
        },
        handleCurrentChange(val) {    //页数改变
            this.pageId = val
            this.getList()
        },
        setList:function(row){  //修改
            let that=this;
            that.service({
                url:'/ResearchObject/SaveBreastOutpatient',
                method:'post',
                data:{
                        ...row
                }
                }).then(response=>{
                        that.$message({
                        message: '修改成功',
                        type: 'success'
                    });
                    that.getList()
                }).catch(data=>{
                    that.getList()
            })
        },
        getList(){           //获取一级信息列表
            let that=this
            that.loading=true
            that.service({
                url:'/ResearchObject/GetBreastOutpatient',
                method:'get',
                params:{
                    pageCount:(that.pageId-1),
                    pageSize:that.pageSize,
                        ...that.searchData,
                    startDate:that.timeDate?that.timeDate[0]:'',
                    endDate:that.timeDate?that.timeDate[1]:'',
                }
                }).then(response=>{
                    that.tableData=response.dtData;
                    that.total =parseInt(response.dtData[0].TotalCount);
                    that.loading=false
                }).catch(data=>{
                that.loading=false
            })
        },
        checkList:function(){
            this.pageId=1;
            this.pageSize=10;
            this.total=null;
            this.getList()
            let storageObj=this.searchData;
            this.searchData.comName=this.CtyIds;
        },
        GetNurse:function(){
            let that=this;
            that.service({
                url:'/ResearchObject/GetLactationConsultant',
                method:'get',
                params:{

                }
            }).then(response=>{
	            let options=response.dtData
	            for(let i of options){    //处理姓名账号不一致，Nan
		            i.Name=i.Name || ''
		            let username=i.Surname+i.Name
		            username=='undefined'?username=i.UserCode:username=username
		            i.icons=username
	            }
                that.optionsNurse=response.dtData;
            }).catch(data=>{

            })
        },
        changeNurse:function(row,val){
            let that=this;
            this.$confirm('更换健康访谈人员后，请重新填写访谈时间, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.optionsNurse.forEach(function (item) { //绑定ID
                    if(item.icons==val){
                        row.NurseId=item.SYS_ID
                    }
                })
                row.FollowUpTime=''
                this.setList(row)
            }).catch(() => {
                that.$message({
                    message:'已取消',
                    type:'info'
                })
                that.getList()
            });
        }
    }
  }
function addZero(s){
    return s < 10 ? '0' + s: s;
}
function dateForm(data){
    return   new Date(data).getFullYear()+'-'+addZero((new Date(data).getMonth()+1))+'-'+addZero(new Date(data).getDate())
}
function WeeksBetw(date1,date2) {  //计算日期之间相差得天数
	var _dt1=new Date(date1);
	var _dt2=new Date(date2);
	var dt1=_dt1.getTime();
	var dt2=_dt2.getTime();
	return parseInt(Math.abs(dt1- dt2)/1000/60/60/24);//这里是计算天数,如果想获得周数则在该返回值上再除以7
}
</script>
<style scoped lang="scss">
    .formX{
    .top{
        text-align: center;
    }
    ul{
    li{
        margin:20px;
    h3{
        color: #606266;
        font-weight: normal;
    }
    h5{
        font-weight: normal;
        margin:5px 0;
    }
    p{
        color: #999999;
        margin-bottom: 10px;
        margin:10px 0px;
    }
    }
    }
    }
    .click_line{cursor: pointer;color:#409EFF;}
    .fade-enter-active, .fade-leave-active {
        transition: opacity .4s;
    }
    .fade-enter, .fade-leave-to{
        opacity: 0;
    }
    .formPlebek{color:#0066FF }
    .pagination-fixed{
     position: static;
    }
    .excelHidden{display: none !important;}
</style>
